<?php


class important extends connector {

	function important() {
		$this->softbase(true);
	}

	function onmesslist() {
		$this->powercheck(168, 169);
		parent::start_template();

		$MinPageid = $this->fun->accept('MinPageid', 'R');

		$page_id = $this->fun->accept('page_id', 'R');

		$countnum = $this->fun->accept('countnum', 'R');

		$MaxPerPage = $this->fun->accept('MaxPerPage', 'R');
		if (empty($MaxPerPage)) {
			$MaxPerPage = $this->CON['max_list'];
		}
		$db_where = ' WHERE ftid>0';
		$isreply = $this->fun->accept('isreply', 'R');
		if (!empty($isreply)) {
			if ($isreply == 2) $isreply = 0;
			$db_where.=' AND isreply=' . $isreply;
		}
		$isclass = $this->fun->accept('isclass', 'R');
		if (!empty($isclass)) {
			if ($isclass == 2) $isclass = 0;
			$db_where.=' AND isclass=' . $isclass;
		}
		$fgid = $this->fun->accept('fgid', 'R');
		if (!empty($fgid)) {
			$db_where.=' AND fgid=' . $fgid;
		}


		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitkey = empty($limitkey) ? 'ftid' : $limitkey;

		$limitclass = $this->fun->accept('limitclass', 'R');
		$limitclass = empty($limitclass) ? 'DESC' : $limitclass;
		$db_table = db_prefix . 'form_time';
		if (!empty($countnum)) {
			$countnum = $this->db_numrows($db_table, $db_where);
			exit($countnum);
		}
		$sql = 'SELECT * FROM ' . $db_table . $db_where . ' ORDER BY ' . $limitkey . ' ' . $limitclass . ' LIMIT ' . $MinPageid . ',' . $MaxPerPage;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$rsList['formgroupname'] = $this->get_form_purview($rsList['fgid'], 'formgroupname');
			$array[] = $rsList;
		}
		$this->fun->setcookie($this->fun->noncefile() . 'pgid', $page_id, 600);
		$this->ectemplates->assign('array', $array);
		$this->ectemplates->assign('isclass', $isclass);
		$this->ectemplates->assign('limitkey', $limitkey);
		$this->ectemplates->assign('limitclass', $limitclass);
		$this->ectemplates->assign('sql', $sql);
		$this->ectemplates->display('form/form_mess_list');
	}

	function onsearch() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$bbstype = $this->get_bbstype_array(0, $lng);
		$this->ectemplates->assign('bbstype', $bbstype['list']);
		$this->ectemplates->display("form/form_search");
	}

	function onread() {
		$this->powercheck(168, 241);
		parent::start_template();
		$tab = $this->fun->accept('tab', 'R');
		$tab = empty($tab) ? 'true' : $tab;
		$ftid = $this->fun->accept('ftid', 'G');
		$forumtype = $this->get_formcontent($ftid);
		$form = $this->get_form_purview($forumtype['fgid']);
		$attrread = $this->get_formatt($forumtype['fgid'], false);
		$forumtype['formgroupname'] = $form['formgroupname'];

		if (!empty($forumtype['did'])) {
			$docread = $this->get_documentview($forumtype['did']);
			$docread['readlink'] = $this->get_link('doc', $docread, $docread['lng']);
		}

		if (!empty($forumtype['userid'])) {
			$memread = $this->get_member(null, $forumtype['userid']);
		}

		if (!empty($forumtype['attrvalue'])) {
			$value = unserialize($forumtype['attrvalue']);
			unset($forumtype['attrvalue']);
		}
		if (is_array($value)) {
			$attlist = $this->fun->array_merge($attrread, $value);
		}
		$this->ectemplates->assign('read', $forumtype);
		$this->ectemplates->assign('attlist', $attlist);
		$this->ectemplates->assign('is_email', $this->CON['is_email']);
		$this->ectemplates->assign('form', $form);
		$this->ectemplates->assign('memread', $memread);
		$this->ectemplates->assign('docread', $docread);
		$this->ectemplates->assign('tab', 'true');
		$this->ectemplates->assign('type', $type);
		$this->ectemplates->display('form/form_mess_read');
	}

	function onsave() {
		parent::start_template();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$ftid = $this->fun->accept('ftid', 'P');
		$fvid = $this->fun->accept('fvid', 'P');
		if (empty($ftid) || empty($fvid)) exit('false');
		$email = $this->fun->accept('email', 'P');
		$isreply = $this->fun->accept('isreply', 'P');
		$content = $this->fun->accept('content', 'P');

		$db_table = db_prefix . 'form_time';
		$db_table2 = db_prefix . 'form_value';
		$date = time();
		if ($inputclass == 'edit' && $isreply == 0) {
			$this->powercheck(168, 241);
			$username = $this->esp_username;
			$db_where = 'ftid=' . $ftid;
			$db_set = "isreply=1,isclass=1,retime=$date,username='$username'";
			$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$db_set = "recontent='$content'";
			$this->db->query('UPDATE ' . $db_table2 . ' SET ' . $db_set . ' WHERE ' . $db_where);
			if ($this->CON['is_email'] && $isreply == 0) {
				$this->formmailsend(162, $ftid);
			}
			$this->writelog($this->lng['formmessmain_edit_log'], $this->lng['log_extra_ok'] . ' ftid=' . $ftid . ' username=' . $username);
			exit('true');
		} else {
			exit('true');
		}
	}

	function ondel() {
		$this->powercheck(168, 242);
		$db_table = db_prefix . 'form_time';
		$db_table2 = db_prefix . 'form_value';
		$selectinfoid = $this->fun->accept('messselectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$db_where = "ftid=$infoarray[$i]";
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where);
			$this->db->query('DELETE FROM ' . $db_table2 . ' WHERE ' . $db_where);
		}
		$this->writelog($this->lng['formmessmain_del_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		exit('true');
	}

	function onsetting() {
		$this->powercheck(168, 243);
		$db_table = db_prefix . 'form_time';
		$selectinfoid = $this->fun->accept('messselectinfoid', 'P');
		$selectinfoid = $selectinfoid . '0';
		if (empty($selectinfoid)) exit('false');
		$value = $this->fun->accept('value', 'P');
		$dbname = $this->fun->accept('dbname', 'P');
		$db_set = "$dbname=$value";
		$db_where = "ftid IN ( $selectinfoid )";
		$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
		$this->writelog($this->lng['formmessmain_log_istype'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		exit('true');
	}

}
?>